package com.is.add.util.DimensionUtil;

import com.is.add.model.OrderBase;

import java.util.ArrayList;
import java.util.List;

/**
 * 财务结算
 * Created by liuming on 2016/5/5.
 */
public class DataCount {
    private String value;            //Key
    private String title;            //显示
    private int orderNum;        //订单预定量
    private double paySum;          //支付额
    private double fee;             //支付服务费
    private double subsidySum;      //补贴额
    private double subsidyFee;      //补贴服务费
    private int count;              //订单数
    private List<DataCount> subSettlements;  //子统计结果/下级维度统计结果
    private List<OrderBase> baseList;         //基础数据
    public DataCount(String title){
        this.value=title.split("-")[0];
        this.title=title.split("-")[1];
        this.count=0;
        this.paySum=0.0;
        this.orderNum=0;
        this.fee=0.0;
        this.subsidyFee=0.0;
        this.subsidySum=0.0;
        this.subSettlements=new ArrayList<>();
    }

    public List<OrderBase> getBaseList() {
        if(this.subSettlements.size()>0){
            return null;
        }
        return baseList;
    }

    void setBaseList(List<OrderBase> baseList) {
        this.baseList = baseList;
    }

    void subSettlementAppend(DataCount ss){
        this.subSettlements.add(ss);
    }
    void doSum(){
        for(DataCount s:this.subSettlements){
            this.countAppend(s.getCount())
                    .paySumAppend(s.getPaySum())
                    .orderNumAppend(s.getOrderNum())
                    .feeAppend(s.getFee())
                    .subsidyFeeAppend(s.getSubsidyFee())
                    .subsidySumAppend(s.getSubsidySum());
        }
    }

    DataCount countAppend(int count){
        this.count+=count;
        return this;
    }
    DataCount paySumAppend(double paySum){
        this.paySum+=paySum;
        return this;
    }
    DataCount orderNumAppend(int orderNum){
        this.orderNum+=orderNum;
        return this;
    }
    DataCount feeAppend(double fee){
        this.fee+=fee;
        return this;
    }
    DataCount subsidyFeeAppend(double subsidyFee){
        this.subsidyFee+=subsidyFee;
        return this;
    }
    DataCount subsidySumAppend(double subsidySum){
        this.subsidySum+=subsidySum;
        return this;
    }

    public String getValue() {
        return value;
    }

    public String getTitle() {
        return title;
    }

    public int getOrderNum() {
        return orderNum;
    }

    public double getPaySum() {
        return paySum;
    }

    public double getFee() {
        return fee;
    }

    public double getSubsidySum() {
        return subsidySum;
    }

    public double getSubsidyFee() {
        return subsidyFee;
    }

    public int getCount() {
        return count;
    }

    //总服务费
    public double getFeeSum() {
        return this.fee+this.subsidyFee;
    }

    //结算额
    public double getSettlementSum() {
        return this.paySum-this.fee-this.subsidyFee;
    }
    //总金额
    public double getTotalSum(){
        return this.paySum+this.subsidySum;
    }
    public List<DataCount> getSubSettlements() {
        return subSettlements;
    }
}
